package com.credit.myapplication

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.credit.anypermission.permission.PermissionBase
import com.permissionx.guolindev.PermissionMediator
import com.permissionx.guolindev.PermissionX

class XPermission : PermissionBase() {

    private lateinit var xPermissions: PermissionMediator

    override fun setActivity(activity: FragmentActivity) {
        super.setActivity(activity)
        xPermissions = PermissionX.init(activity)
    }

    override fun setFragment(fragment: Fragment) {
        super.setFragment(fragment)
        xPermissions = PermissionX.init(fragment)
    }

    override fun request() {
        xPermissions.permissions(mUnGrantedPermissions.peek()!!).request { _, _, _ ->
            if (mUnGrantedPermissions.size == 0) {
                onSuccess()
            } else {
                again()
            }
        }
    }


}